package org.gzc.util;

/**
 * 统一JSON数据格式工具
 */
public class ResultUtil<T> {
    private int code;
    private String msg = "";
    private T data;

    public static ResultUtil success = new ResultUtil<>(0, "success");
    public static ResultUtil failed = new ResultUtil<>(-1, "error");

    public ResultUtil() {
    }

    public ResultUtil(int code, String msg) {
        this.msg = msg;
        this.code = code;
    }

    public ResultUtil code(int code) {
        this.code = code;
        return this;
    }

    public ResultUtil msg(String msg) {
        this.msg = msg;
        return this;
    }

    public ResultUtil data(T data) {
        this.data = data;
        return this;
    }


    public int getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    public T getData() {
        return data;
    }


    @Override
    public String toString() {
        return "ResultUtil{" +
                "code=" + code +
                ", msg='" + msg + '\'' +
                ", data=" + data +
                '}';
    }
}
